package com.ccy.legendary.Operation.imp;

import com.ccy.legendary.Operation.JudgeService;
import com.ccy.legendary.Operation.pojo.ActRemark;
import com.ccy.legendary.base.data.PersonsData;
import com.ccy.legendary.base.pojo.Person;
import com.ccy.legendary.base.pojo.PersonStatus;
import com.ccy.legendary.base.pojo.ResultBean;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service("judgeServiceTest")
public class JudgeServiceTestImpl implements JudgeService {

    @Override
    public ResultBean startJudge() {
        Map<String, Person> persons = PersonsData.getPersonData();
        ResultBean resultBean = new ResultBean();
        if(persons.size()<=1){
            resultBean.addMessage("当前房间不足2人");
            return resultBean;
        }
        for(Person person:persons.values()){
            if(!PersonStatus.prepare.equals(person.getPersonStatus())){
                resultBean.addMessage("有玩家未准备好");
                return resultBean;
            }

        }
        resultBean.setStatus(true);
        resultBean.addMessage("所有玩家已准备好，当前人数为"+persons.size()+"游戏开始");
        return resultBean;
    }

    @Override
    public List<String> ackJudge(String userCode) {
        Person person = PersonsData.getPersonData().get(userCode);
        List<String> messages = new ArrayList<>();
        person.setRunCount(person.getRunCount()+1);
        var message = ActRemark.runCountRemark(person.getRunCount());
        messages.add(message);
        return messages;
    }

    @Override
    public List<String> runJudge(String userCode, Integer point) {
        Person person = PersonsData.getPersonData().get(userCode);
        List<String> messages = new ArrayList<>();
        messages.add(ActRemark.runRemark(userCode,point));
        if("6".equals(point)){
            person.setRunCount(person.getRunCount()+1);
            messages.add("点数为6，再掷一次");
        }
        person.setRunCount(person.getRunCount()-1);
        return null;
    }

}
